﻿/*
 * Handles Scrolling Text.
 * Author: Bachir
 * 
 */

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;

namespace Homebound
{
    class ScrollingText
    {
        SpriteFont font;
        public string label;
        public Vector2 position, direction;
        public static Random rand = new Random();
        public float speed;
        public bool expired;
        public Color color;
        public double time;

        public ScrollingText(SpriteFont font, string label, Vector2 position, Color color)
        {
            this.font = font;
            this.label = label;
            Vector2 length = font.MeasureString(label);
            this.position = position;
            this.position.X -= length.X / 2;
            this.direction = Vector2.Normalize(new Vector2((float)rand.NextDouble() / 1 - 0.5f, -1));
            this.expired = false;
            this.speed = 1.50f;
            this.color = color;
            this.time = 0;
        }

        public void Update(GameTime gameTime)
        {
            this.position += speed * direction;
            time += gameTime.ElapsedGameTime.TotalMilliseconds;
            if (time > 2000)
            {
                expired = true;
            }
        }

        public void Draw(SpriteBatch spriteBatch)
        {
            spriteBatch.DrawString(font, label, position, color);
        }
    }
}
